
package Convertisseur;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeDateDay {

	private static String dateFormat = "dd.MM.yyyy/HH:mm:ss";
	private static String dateFormat2 = "yyyy-MM-dd HH:mm:ss";
	private static String dateFormat3 = "yyyy-MM-dd";
	private static String dateFormat4 = "yyyy-MM-dd HH.mm.ss";
	/**
	 * The date type is converted to string type
	 * @param date
	 * @return
	 */
	public static String FormatDateToString(Date date){
	    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
	    return sdf.format(date);
	}
	public static String FormatDateToString2(Date date){
	    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat2);
	    return sdf.format(date);
	}
	public static String FormatDateToString3(Date date){
	    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat3);
	    return sdf.format(date);
	}
	public static String FormatDateToString4(Date date){
	    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat4);
	    return sdf.format(date);
	}
	
	/** 
	 * Get the date value of the specified day of the year. Using the calendar 
	 * object we can define our calendar for a specific day of the year.
	 * @param dayOfYear
	 * 
	 */
	public static String DayOfYearToDate(int dayOfYear){

	    Calendar calendar = Calendar.getInstance();
	    calendar.set(Calendar.DAY_OF_YEAR, dayOfYear);
	    Date date = calendar.getTime();
	    String s = FormatDateToString(date);
	    return s;
	 
	}
	
	/**
	 * Get the date for a specific day of year and for a specific year, 
	 * you can also pass the year information to the calendar object.
	 * 
	 * @param dayOfYear
	 * @param year
	 */
	public static String DayOfYearToDate(int dayOfYear, int year){

	 
	    //int year = 2004;
	    Calendar calendar = Calendar.getInstance();
	    calendar.set(Calendar.DAY_OF_YEAR, dayOfYear);
	    calendar.set(Calendar.YEAR, year);
	    Date date = calendar.getTime();
	    String s = FormatDateToString(date);
	    return s;
	}
	
	public  static String getNowTime(){
		Date date = new Date(System.currentTimeMillis());
		String s = FormatDateToString2(date);
	    return s;
	}
	public  static String getNowTime2(){
		Date date = new Date(System.currentTimeMillis());
		String s = FormatDateToString4(date);
	    return s;
	}
	public  static String getNowDay(){
		Date date = new Date(System.currentTimeMillis());
		String s = FormatDateToString3(date);
	    return s;
	}
	
	public static void main(String [] args){
		
		System.out.println(DayOfYearToDate(73));
		System.out.println(DayOfYearToDate(60, 2012));
		System.out.println(TimeDateDay.getNowTime());
	}

}
